package th.co.exat.uap.model;

import com.channgam.dbmlib.sql.MySQLJDBC;
import com.channgam.dbmlib.sql.iDataAdapter;
import th.co.exat.uap.config.Config;

public class Except {

    private static iDataAdapter i;
    private String id;
    private String plateId;
    private String province;
    private String brandId;
    private String colorId;
    private String carType;
    private String sPolId;

    public static int check(String plateId,
            String province, String dateTime) throws Exception {
        int status = 0;
        i = new MySQLJDBC(Config.getMySqlHost(),
                Config.getMySqlUsername(),
                Config.getMySqlPassword(),
                Config.getMySqlDbname());
        i.connect();
        String sql = "SELECT count(*) AS c "
                + "FROM uap_mst_except e "
                + "WHERE plate_id = '" + plateId + "' "
                + "AND province = '" + province + "' "
                + "AND start_datetime <= '" + dateTime + "' "
                + "AND end_datetime >= '" + dateTime + "' ";
        i.query(sql);

        while (i.resultNext()) {
            if (i.result().getInt("c") == 0) {
                status = 0;
            } else {
                status = 1;
            }
        }

        i.close();
        return status;
    }
}
